# Maintainer: TBK <alpine@jjtc.eu>
# Contributor: TBK <alpine@jjtc.eu>

# when changing _ver we *must* bump _rel
_name=sdfat
_ver=2.1.8.2
_rel=0

_flavor=${FLAVOR:-vanilla}
_kpkg=linux-$_flavor
_kver=4.19.90
_krel=0

_kpkgver="$_kver-r$_krel"
_kabi="$_kver-$_krel-$_flavor"

pkgname=$_name-$_flavor
pkgver=$_kver
pkgrel=$(( _krel + _rel ))

pkgdesc="FAT12/16/32(VFAT)/64(exFAT) filesytems kernel module"
url="https://github.com/TBK/kernel-sdfat"
arch=""
license="GPL-2.0-or-later"
options="!check" # no test suite
depends="$_kpkg=$_kpkgver util-linux"
makedepends="$_kpkg-dev=$_kpkgver linux-headers"
install_if="$_kpkg=$_kpkgver $_name"
source="$_name-$_ver.tar.gz::https://github.com/TBK/kernel-sdfat/archive/$_ver.tar.gz
	mount.exfat
	"
builddir="$srcdir/kernel-$_name-$_ver"

prepare() {
	default_prepare
	local _kapkbuild=../../main/linux-$_flavor/APKBUILD
	if [ -f $_kapkbuild ]; then
		(	. $_kapkbuild
			pkgname="$_name-$_flavor"
			[ "$_kver" != "$pkgver" ] && die "please update _kver to $pkgver"
			[ "$_krel" != "$pkgrel" ] && die "please update _krel to $pkgrel"
			return 0
		)
	fi
}

build() {
	unset LDFLAGS
	make CONFIG_SDFAT_FS=m CONFIG_USE_FOR_EXFAT=y CONFIG_USE_FOR_VFAT=y KERNELDIR=/lib/modules/$_kabi/build
}

package() {
	local module=""
	for module in *.ko; do
		install -v -D -m644 ${module} \
			"$pkgdir/lib/modules/$_kabi/fs/${module}"
	done

	install -Dm0755 "$srcdir"/mount.exfat "$pkgdir/sbin/mount.exfat"
}

sha512sums="566050709952aae35d5e68e88231573ead2f6e5c883bff5dce0055a8df9e91318794cd2938b49c51e250e4e5c61083195ce851ccb7f7537317912e1246ea5a83  sdfat-2.1.8.2.tar.gz
85c54950e69e342221343b8b542fda47f80b9a7104e1097a7f1c9a09f69758ef8881c238d2740f3a21aa2b5cdcb3b9b8224c731ec2e39fa4632f56c2df85bc84  mount.exfat"
